﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml;
using System.Data.SqlClient;
using OgilvyOne.Model;
using OgilvyOne.BLL;
using System.Web.Caching;

public partial class DataBaseManage_LogManage : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.headers.Text = new ColumnBll().LayeridSysColumnNaiv(Layerid);
            string layerid = Request["layerid"];
            PopedomValidate(layerid, QUERY);
            showindex();
        }
    }
    protected void btnSwitch_Click(object sender, EventArgs e)
    {
        PopedomValidate(layerid, MOD);
        Response.Redirect("log_switch.aspx?layerid=" + Request.Params["layerid"]);
        return;
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        Response.Redirect("log_delete.aspx?layerid=" + Request.Params["layerid"]);
        return;
    }


    protected void GridView1_PageIndexChanging1(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        DataSet ds = new LogManageBLL().GetLog("");
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }
    protected void btnPrev_Click(object sender, EventArgs e)
    {
        if (this.GridView1.PageIndex > 0)
        {
            this.GridView1.PageIndex = this.GridView1.PageIndex - 1;
            showindex();
        }
        else
        {

        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        if (this.GridView1.PageIndex < this.GridView1.PageCount)
        {
            this.GridView1.PageIndex = this.GridView1.PageIndex + 1;
            showindex();
        }
        else
        {

        }
    }
    protected void btnLast_Click(object sender, EventArgs e)
    {
        this.GridView1.PageIndex = this.GridView1.PageCount;
        showindex();
    }
    protected void btnGo_Click(object sender, EventArgs e)
    {
        try
        {
            int pa = int.Parse(this.txtNewPageIndex.Text.ToString());
            if (1 <= pa || pa <= this.GridView1.PageCount)
            {
                this.GridView1.PageIndex = pa - 1;
                showindex();
            }
            else
            {
                Response.Write("<script>alert('请输入正确的页码!')</script>");
                this.txtNewPageIndex.Text = (this.GridView1.PageIndex + 1).ToString();
            }
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.ToString() + "!')</script>");
            this.txtNewPageIndex.Text = (this.GridView1.PageIndex + 1).ToString();
        }
    }
    protected void showindex()
    {
        DataSet ds = new LogManageBLL().GetLog("");
        GridView1.DataSource = ds;
        GridView1.DataBind();

        int num = ds.Tables[0].Rows.Count;
        int index = this.GridView1.PageIndex + 1;
        int cont = this.GridView1.PageCount;
        this.label1.Text = "当前第" + index.ToString() + "页    共" + cont.ToString() + "页";
        this.label2.Text = "共" + num.ToString() + "条数据";
        this.txtNewPageIndex.Text = index.ToString();
        if (GridView1.Rows.Count == 0)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("USERNAME");
            dt.Columns.Add("LOGCONTENT");
            dt.Columns.Add("EXECUTETIME");
            dt.Rows.Add(dt.NewRow());
            GridView1.DataSource = dt;
            GridView1.DataBind();
            int columncount = dt.Columns.Count;
            GridView1.Rows[0].Cells.Clear();
            GridView1.Rows[0].Cells.Add(new TableCell());
            GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
            GridView1.Rows[0].Cells[0].Text = "没有相关信息";
            GridView1.Rows[0].Cells[0].Style.Add("text-align", "center");
        }
        if (this.GridView1.PageCount != 1)
        {
            if (this.GridView1.PageIndex == 0)
            {
                btnFirst.Visible = false;
                btnPrev.Visible = false;
                btnNext.Visible = true;
                btnLast.Visible = true;
            }
            else if (this.GridView1.PageIndex == this.GridView1.PageCount - 1)
            {
                btnFirst.Visible = true;
                btnPrev.Visible = true;
                btnNext.Visible = false;
                btnLast.Visible = false;
            }

            else
            {
                btnFirst.Visible = true;
                btnPrev.Visible = true;
                btnNext.Visible = true;
                btnLast.Visible = true;
            }
        }
        else
        {
            btnFirst.Visible = false;
            btnPrev.Visible = false;
            btnNext.Visible = false;
            btnLast.Visible = false;
            btnGo.Visible = false;
            label1.Visible = false;
            label2.Visible = false;
            txtNewPageIndex.Visible = false;
        }
    }
    protected void btnFirst_Click1(object sender, EventArgs e)
    {
        this.GridView1.PageIndex = 0;
        showindex();
    }
}
